﻿@model LayoutEntity
@{
    Layout = Layouts.PageDesign;
    Style.Reqiured("Layout").AtHead();
    Style.Reqiured("Easy").AtHead();
    Script.Reqiured("jQueryUi").AtFoot();
    Script.Reqiured("PageDesign").AtFoot();
    if (Model == null)
    {
        return;
    }
    //Stack<string> colors = new Stack<string>(new[] { "blue", "lightBlue", "red", "green", "orange" });
}

<input type="hidden" id="save-widget-zone-url" value="@Url.Action("SaveWidgetZone", "Widget")" />
<input type="hidden" id="append-widget-url" value="@Url.Action("AppendWidget", "Widget")" />
<input type="hidden" id="pageId" value="@Model.Page.ID" />
@for (int i = 0; i < Model.Html.Count; i++)
{
    var item = Model.Html[i];
    if (item.Html == ZoneEntity.ZoneTag)
    {
        i++;
        var zoneId = Model.Html[i].Html;
        if (zoneId.IsNotNullAndWhiteSpace())
        {
            if (Model.ZoneWidgets.ContainsKey(zoneId))
            {
                foreach (var widgetPart in Model.ZoneWidgets[zoneId].OrderBy(m => m.Widget.Position).ThenBy(m => m.Widget.WidgetName))
                {
                    @Html.DesignWidget(new DesignWidgetViewModel(widgetPart, Model.Page.ID));
                }
            }
            if (Model.Zones.Any(m => m.HeadingCode == zoneId))
            {
                <input type="hidden" class="zoneId" value="@zoneId" />
                <div class="zoneName">
                    <a title="添加内容"
                       class="add-widget btn btn-black btn-sm"
                       href="@Url.Action("SelectWidget", "WidgetTemplate", new {pageId = Model.Page.ID, ZoneId = zoneId})">
                        <i class="glyphicon glyphicon-plus"></i>
                        @L("添加内容") | @Model.Zones.First(m => m.HeadingCode == zoneId).ZoneName
                        
                    </a>
                    @if (ViewBag.CanPasteWidget == true)
                    {
                        <a class="paste-widget btn btn-danger btn-sm" title="@L("粘贴复制的内容到该区域")"
                           href="@Url.Action("Paste", "Widget", new { PageID = Model.Page.ID, ZoneID = zoneId })">
                            <i class="glyphicon glyphicon-paste"></i>
                            @L("粘贴")
                        </a>
                    }
                </div>
            }
        }
        i++;
    }
    else
    {
        @Html.Raw(item.Html)
    }
}
<div class="templates">
    <div class="tool-open glyphicon glyphicon-chevron-right"></div>
    <ul>
        @foreach (WidgetBase item in Model.Templates.OrderByDescending(m => m.IsSystem).ThenBy(m => m.Position))
        {
            <li id="template_@item.ID" class="widget-design" data-add="true" data-id="@item.ID">
                <img title="@item.WidgetName" class="template" src="@Url.Content(item.Thumbnail.IsNullOrWhiteSpace() ? "~/images/template.png" : item.Thumbnail)" />
                @if (!item.IsSystem)
                {
                    <img data-id="@item.ID" data-url="@Url.Action("CancelTemplate", "Widget")" class="delete-template" src="~/images/close_red.png" />
                }
            </li>
        }
    </ul>
</div>